package net;

import java.net.ServerSocket;

import logic.GameRules;
import logic.Manager;

public class UserServer {
	ServerSocket server = null;
	int connections = 0;
	boolean noGameOver = false;
	public Manager gameManager;
	public GameRules gameRules;
	
	public UserServer(){
		gameManager = new Manager(2);
		gameRules = new GameRules();
		initServer();

	    while(connections < 2){
	    	waitConnections();
	    }
	    while(noGameOver){
	    	try {
				server.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
	}
	
	public void initServer(){
		try{
			server = new ServerSocket(9999);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void waitConnections(){
		try {
			connections++;
			new GameServer(server.accept());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
